package edu.vu.colorsplosion;

import java.util.Random;

public class GameLevel {

    private int mCurrentLevel;
    private int[] mShipSize = {15,17,19,21,23,25,27};
    private int[] mMinShapeSize = {32,10,24,20,16,12};
    private int[] mSpeed = {5,5,4,4,3,3};
    
    public GameLevel(int level){
        mCurrentLevel = level;
    }
    
    /**
     * @return the current level
     */
    public int currentLevel(){
        return mCurrentLevel;
    }
    
    public int shipSize(){
        return mShipSize[mCurrentLevel-1];
    }
    
    /**
     * Increments the game level if the game has not been won
     * @return: true if game has been won, else false
     */
    public boolean levelUp(){
        if (mCurrentLevel < 7){
            mCurrentLevel++;
            return false;
        } else {
            return true;
        }
    }
    
    /**
     * Get the parameters for creating a new enemy shape
     * @return integer array containing shape's: minSize, maxSize, hueR, hueG, hueB, speed, pointValue
     */
    public float[] getParams(){
        float[] params = new float[7];
        int seed;
        
        Random random = new Random();
        
        if (mCurrentLevel == 1){
            seed = 0; // 0
        } else if (mCurrentLevel == 2){
            seed = random.nextInt(5); // 0:4, then change all the 2's and 3's into 0's, all 4's into 1's (so 3/5 white, 2/5 red)
            if (seed == 2 || seed == 3){
                seed = 0;
            } else if (seed == 4){
                seed = 1;
            }
        } else if (mCurrentLevel == 3){
            seed = random.nextInt(3); // 0:2
        } else if (mCurrentLevel == 7){
            seed = random.nextInt(5)+1; // 1:5
        } else {
            seed = random.nextInt(mCurrentLevel); // 0:(level-1)
            //TODO make levels above three some sort of weighted random value instead of even distribution
        }
        
        if (seed == 0){ //white shape, always good
            params[2] = 1;
            params[3] = 1;
            params[4] = 1;
            params[6] = 10;
        } else if (seed == 1){ //red shape, always bad
            params[2] = 1;
            params[3] = 0;
            params[4] = 0;
            params[6] = -5;
        } else if (seed == 2){ //yellow shape
            params[2] = 1f;
            params[3] = 0.7f;
            params[4] = 0;
            params[6] = 25;
        } else if (seed == 3){ //green shape
            params[2] = 0;
            params[3] = 1;
            params[4] = 0;
            params[6] = 40;
        } else if (seed == 4){ //blue shape
            params[2] = 0;
            params[3] = 0;
            params[4] = 1;
            params[6] = 80;
        } else /*if (seed == 5)*/ { //purple shape
            params[2] = 1;
            params[3] = 0;
            params[4] = 1;
            params[6] = 160;
        }
        params[0] = mMinShapeSize[seed];
        params[1] = params[0] + 4;
        params[5] = mSpeed[seed];
        
        if (mCurrentLevel == 7 && seed != 1){
            params[0] = 8;
            params[1] = 10;
            params[5] = 2;
            params[6] = 250;
        }
        
        return params;
    }
}
